'''
 UI自动化测试定制化开发
    用于测试创建订单及其主流程
'''


import pytest
import logging
import allure
import utils.allure_step as allure_step
from utils.sele_Util import sele_Util
from time import sleep

logger = logging.getLogger()
sele_util = sele_Util('Chrome')


@pytest.fixture(scope='module', autouse=True)
def flow01_fixture(url_fixture):
    sele_util.open(url_fixture['Url'])
    yield
    sleep(3)
    sele_util.quit()


@pytest.fixture(scope='module', autouse=True)
def execl_fixture():
    file_url = 'data/TMS/运单流程测试.xlsx'
    yield file_url


@allure.suite('TMS主流程：登录+发布货源+确认签收+请款+核销（应收、应付）')
class TestFlow01:

    # 测试登录流程
    @allure.title('登录测试')
    @allure.story('进行登录测试')
    def test01_login(self, execl_fixture):
        logger.info('开始登录测试')
        sheet_name = '登录'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('运单标记完成测试')
    @allure.story('进行运单标记完成测试')
    def test02_order_finish(self, execl_fixture):
        logger.info('开始运单标记完成测试')
        sheet_name = '运单完成'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('申请付款测试')
    @allure.story('进行申请付款测试')
    def test03_ask_pay(self, execl_fixture):
        logger.info('开始申请付款测试')
        sheet_name = '申请付款'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('拒绝付款审核测试')
    @allure.story('进行拒绝付款审核测试')
    def test04_refuse_pay(self, execl_fixture):
        logger.info('开始拒绝付款审核测试')
        sheet_name = '拒绝审核'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('通过审核测试')
    @allure.story('进行通过审核测试')
    def test05_reapply_pay(self, execl_fixture):
        logger.info('开始通过审核测试')
        sheet_name = '通过审核'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('应付核销测试')
    @allure.story('进行应付核销测试')
    def test06_pay_verify(self, execl_fixture):
        logger.info('开始应付核销测试')
        sheet_name = '应付核销'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)

    @allure.title('应收核销测试')
    @allure.story('进行应收核销测试')
    def test07_income_verify(self, execl_fixture):
        logger.info('开始应收核销测试')
        sheet_name = '应收核销'
        allure_step.service(sele=sele_util, file_url=execl_fixture, sheet_name=sheet_name)
